﻿using System.IO;
using System.Xml;

namespace CodeLibrary.XML.Utils
{
    public static class XMLHelper
    {
        public static void AdjustXMLFile(string filename)
        {
            FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
            StreamReader sr = new StreamReader(fs);
            string strContent = sr.ReadToEnd();
            sr.Close();
            fs.Close();
            StreamWriter sw = new StreamWriter(filename);
            sw.Write(strContent.Replace("&amp;amp;", "&amp;"));
            sw.Flush();
            sw.Close();
        }

        public static string GetNodeText(XmlNode node)
        {
            if (node != null)
            {
                return node.InnerText;
            }
            return "";
        }

        public static string GetNodeAttribute(XmlNode node, string name)
        {
            if (node.Attributes != null)
            {
                return node.Attributes[name].InnerText;
            }
            return "";
        }
    }
}
